using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LeadTracker.Models;

namespace LeadTracker.Models.Tests.Generated
{
	public partial class LeadModelTests
	{

		
		[TestMethod]
		public void Title_NotifyPropertyChangedTest()
        {
	
            var objectUnderTest = CreateObject();
            var events = new List<PropertyChangedEventArgs>();
            ((INotifyPropertyChanged)objectUnderTest).PropertyChanged += (s, e) => events.Add(e);

			//Setting the value to the current value should always work
			var originalValue = objectUnderTest.Title;
			objectUnderTest.Title = originalValue;
			Assert.AreEqual(originalValue, objectUnderTest.Title);
			Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));

			//For each of the following, it should either work or throw an ArgumentException 

			try 
			{
				events.Clear();
				var expectedValue = (string)null;
				var valueChanged = !Object.Equals(expectedValue, objectUnderTest.Title );
				objectUnderTest.Title = expectedValue;

				if (valueChanged)
					Assert.IsTrue(events.Any(e => e.PropertyName == "Title"));
				else
					Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));
			}
			catch (ArgumentException) 
			{
				//OK
			}

			try 
			{
				events.Clear();
				var expectedValue = "";
				var valueChanged = !Object.Equals(expectedValue, objectUnderTest.Title );
				objectUnderTest.Title = expectedValue;

				if (valueChanged)
					Assert.IsTrue(events.Any(e => e.PropertyName == "Title"));
				else
					Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));
			}
			catch (ArgumentException) 
			{
				//OK
			}

			try 
			{
				events.Clear();
				var expectedValue = "0";
				var valueChanged = !Object.Equals(expectedValue, objectUnderTest.Title );
				objectUnderTest.Title = expectedValue;

				if (valueChanged)
					Assert.IsTrue(events.Any(e => e.PropertyName == "Title"));
				else
					Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));
			}
			catch (ArgumentException) 
			{
				//OK
			}
			
			try 
			{
				events.Clear();
				var expectedValue = "1";
				var valueChanged = !Object.Equals(expectedValue, objectUnderTest.Title );
				objectUnderTest.Title = expectedValue;

				if (valueChanged)
					Assert.IsTrue(events.Any(e => e.PropertyName == "Title"));
				else
					Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));
			}
			catch (ArgumentException) 
			{
				//OK
			}

			for (int i = 0; i < 100; i++)
			{
				try 
				{
					events.Clear();
					var expectedValue = new String('a', i);
					var valueChanged = !Object.Equals(expectedValue, objectUnderTest.Title );
					objectUnderTest.Title = expectedValue;

					if (valueChanged)
						Assert.IsTrue(events.Any(e => e.PropertyName == "Title"));
					else
						Assert.IsFalse(events.Any(e => e.PropertyName == "Title"));
					}
				catch (ArgumentException) 
				{
					//OK
				}
			}
        }


	}
}
